/*----------------------------------------------------------------------------
					Replication file for article
Toni Rodon & Raül Tormos (2022) "The Burden of a Violent Past. 
Formative Experiences of Repression and Support for Secession in Catalonia"
				British Journal of Political Science
Additional details: toni.rodon@upf.edu & rtormos.ceo@gencat.cat 
We advise users to look at the readme file before running the code.
------------------------------------------------------------------------------*/

*User-written Packages
ssc install r2_mz
ssc install fitstat

*Clear Set path
clear

cd " " /*SET YOUR PATH HERE*/

*Open data
use "DATASET repression.dta", clear

*-----------------------------------------*
*---Recoding and creation of variables----*
*-----------------------------------------*

gen gen7dic_difrep = gen7_dic * dif_rep_esq

egen tin_gendif = mean(gen7dic_difrep), by(groupid)
generate tvar_gendif = gen7dic_difrep - tin_gendif



*--------------------------*
*-------Analysis-----------*
*--------------------------*


********************************Table 1**

*Model 1: RE without the cross-level interaction*
xtmelogit indep gen7_dic dif_rep_esq if (naix_ego == 1)|| groupid: , mle variance
estat ic
r2_mz

*Model 2: RE with the cross-level interaction*
xtmelogit indep i.gen7_dic##c.dif_rep_esq  if (naix_ego == 1)|| groupid: gen7_dic, mle variance
estat ic
r2_mz

*Model 3: RE with the cross-level interaction and controls at the two levels*
xtmelogit indep v434 lleng_casa i.gen7_dic##c.dif_rep_esq i.dimensio p_naixcat_mun edatmun_65imes p_homes ///
i.provincia if naix_ego == 1|| groupid: gen7_dic, mle variance
estat ic
r2_mz

*Model 4: RE with the cross-level interaction and controls at the two levels for the period 1991-99*
xtmelogit indep v434 lleng_casa i.gen7_dic##c.dif_rep_esq i.dimensio p_naixcat_mun edatmun_65imes p_homes ///
i.provincia if (naix_ego == 1 & time_dic == 1) || groupid: gen7_dic, mle variance
estat ic
r2_mz

*Model 5: RE with the cross-level interaction and controls at the two levels for the period 2000-16* 
xtmelogit indep v434 lleng_casa i.gen7_dic##c.dif_rep_esq i.dimensio p_naixcat_mun edatmun_65imes p_homes ///
i.provincia if (naix_ego == 1 & time_dic == 2) || groupid: gen7_dic, mle variance
estat ic
r2_mz

*Model 6: Hybrid REWB without controls at the two levels*
xtmelogit indep gen7_dic dif_rep_esq tin_gendif tvar_gendif if naix_ego == 1|| groupidv2: gen7_dic, mle variance
estat ic
r2_mz

*Model 7: Hybrid REWB with controls at the two levels*
xtmelogit indep v434 lleng_casa gen7_dic dif_rep_esq tin_gendif tvar_gendif i.dimensio p_naixcat_mun ///
edatmun_65imes p_homes i.provincia if naix_ego == 1|| groupidv2: gen7_dic, mle variance
estat ic
r2_mz

*Model 8: FE model with municipalities fixed effects*
xi: logit indep gen7_dic dif_rep_esq gen7dic_difrep i.groupid if naix_ego == 1 
fitstat 
r2_mz

*Model 9: FE model with municipalities and years fixed effects**
xi: logit indep gen7_dic dif_rep_esq gen7dic_difrep i.groupid i.any if naix_ego == 1
fitstat 

*Model 10: cFES model with municipalities FE and controlling for effect heterogeneity in gen7_dic and dif_gen7_dic*
logit indep i.gen7_dic##c.dif_rep_esq i.groupid##i.gen7_dic i.groupid#c.dif_rep_esq  if naix_ego == 1
fitstat



********************************Figure 1**


xtmelogit indep i.gen7_dic##c.dif_rep_esq if naix_ego == 1|| groupid: gen7_dic, mle variance
margins gen7_dic, at(dif_rep_esq=(0(1)6)) post
marginsplot, recast(line) recastci(rarea) ///
addplot(hist dif_rep_esq, /// adding histogram marginsplot graph
blcolor(gs10) fcolor(gs10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " ", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)) /// telling Stata to remove title on 2nd y-axis
legend(order( 2 "Oldest cohort" 3 "Rest")))  
graph save 1.gph, replace


xtmelogit indep v434 lleng_casa i.gen7_dic##c.dif_rep_esq i.dimensio p_naixcat_mun edatmun_65imes p_homes ///
i.provincia if naix_ego == 1|| groupid: gen7_dic, mle variance
margins gen7_dic, at(dif_rep_esq=(0(1)6)) post
marginsplot, recast(line) recastci(rarea) ///
addplot(hist dif_rep_esq, /// adding histogram marginsplot graph
blcolor(gs10) fcolor(gs10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " ", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)) /// telling Stata to remove title on 2nd y-axis
legend(order( 2 "Oldest cohort" 3 "Rest")))  
graph save 2.gph, replace

graph combine 1.gph 2.gph, rows(1) ycommon
graph save "Figure 1.gph", replace



********************************Figure 2**

*elections are not useful*
xtmelogit eleccions i.gen7_dic##c.dif_rep_esq if naix_ego == 1|| groupid: gen7_dic, mle variance
margins gen7_dic, at(dif_rep_esq=(0(1)6)) post
marginsplot, recast(line) recastci(rarea) ///
addplot(hist dif_rep_esq, /// adding histogram marginsplot graph
blcolor(gs10) fcolor(gs10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " ", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)) /// telling Stata to remove title on 2nd y-axis
legend(order( 2 "Oldest cohort" 3 "Rest")))  
graph save 1.gph, replace

*better not to get involeved in politics*
xtmelogit noficarse_pol i.gen7_dic##c.dif_rep_esq if naix_ego == 1|| groupid: gen7_dic, mle variance
margins gen7_dic, at(dif_rep_esq=(0(1)6)) post
marginsplot, recast(line) recastci(rarea) ///
addplot(hist dif_rep_esq, /// adding histogram marginsplot graph
blcolor(gs10) fcolor(gs10) /// bar line and fill colors
percent /// histogram bins in "percent" rather than "discrete" (actual)
yaxis(2) /// calls for 2nd y-axis
yscale(alt lcolor() axis(2)) /// scaling on 2nd y-axis
ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " ", /// labels on 2nd y-axis
labcolor() axis(2) tlcolor(black) tlwidth(thin) labsize(small)) /// label options on 2nd y-axis
ytitle(" ", axis(2)) /// telling Stata to remove title on 2nd y-axis
legend(order( 2 "Oldest cohort" 3 "Rest")))  
graph save 2.gph, replace

graph combine 1.gph 2.gph, rows(1) 
graph save "Figure 2.gph", replace





